<?php
  class AuxDbTable extends Zend_Db_Table
  {
      public $__validationMessage='';
      
      public function replace_quotes($string)
      {
            $string = str_replace('<','&#60;',$string);
            $string = str_replace('>','&#62;',$string);
            $string = str_replace('"','&#34;',$string);
            $string = str_replace("'",'&#39;',$string);
            return $string;
      }
    
      public function checkDateFormat($date)
      {
         $date_pattern = '/^[0-9]{4}\-(?:0[1-9]|1[0-2])\-(?:[0-2]?[0-9]|3[0-1])$/'; 
         return preg_match($date_pattern,$date);
      }
    
      public function checkDates($date_start, $date_end)
      {
            $valid = true;
            //date start
            
            $valid_start_date = $valid_end_date = false;
            if(strlen($date_start)>0)
            {
                if(!$this->checkDateFormat($date_start))
                {
                    $this->__validationMessage .= 'Invalid Start Date '.$this->replace_quotes($date_start).'. Format yyyy-mm-dd.<br>';
                    $valid = false;
                } else $valid_start_date = true;
            }
            //date end
            if(strlen($date_end)>0)
            {
                if(!$this->checkDateFormat($date_end))
                {
                    $this->__validationMessage .= 'Invalid End Date '.$this->replace_quotes($date_end).'. Format yyyy-mm-dd.<br>';
                    $valid = false;
                } else $valid_end_date = true;
            }
            // atart and end date
            if($valid_start_date && $valid_end_date)
            {
                if($date_end<$date_start)
                {
                    $this->__validationMessage .= 'Start Date must be less then End Date.<br>';
                    $valid = false;
                }
            }
            return $valid;
      }
  }
?>
